<?php
// +----------------------------------------------------------------------
// | Tpli [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 系统菜单表
// +----------------------------------------------------------------------

namespace app\admin\model;
use app\admin\service\AdminMenu as AdminMenuService;
use think\Model;
use \think\Db;
use \think\Session;
class AdminMenu extends Model
{
  public static function getAllAdminMenu()
  {
    $menu = self::where(['is_display'=>1])->order('orders asc')->select();
    //删除不在当前角色权限里的菜单，实现隐藏
    $admin_cate = Session::get('admin_cate_id');
    $permissions = Db::name('admin_cate')->where(['id'=>$admin_cate])->value('permissions');
    $permissions = explode(',',$permissions);

    foreach ($menu as $k => $val) {
      if($val['type'] == 1 and $val['is_display'] == 1 and !in_array($val['id'],$permissions)) {
        unset($menu[$k]);
      }
    }
    $menus = AdminMenuService::getUrl($menu);
    return $menus;
  }

  public static function menuList()
  {
    $menu = self::order('orders asc')->select();
    $menus = AdminMenuService::menuTree($menu);
    return $menus;
  }

}
?>